﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using IBatisNet.DataMapper.TypeHandlers;

namespace Pg.BioMedics.SDR.Data.TypeHandlers
{
    /// <summary>
    /// This type handler extends mapper with support for nullable Guids
    /// </summary>
    public class GuidHandler : ITypeHandlerCallback
    {
        #region ITypeHandlerCallback Members

        public object GetResult(IResultGetter getter)
        {
            if (String.IsNullOrEmpty(getter.Value as string))
                return null;
            else
                return new Guid(getter.Value as string);
        }

        public object NullValue
        {
            get 
            {
                return null;
            }
        }

        public void SetParameter(IParameterSetter setter, object parameter)
        {
            if (parameter == null)
                setter.Value = null;
            else
                setter.Value = parameter.ToString();
        }

        public object ValueOf(string s)
        {
            return new Guid(s);
        }

        #endregion
    }
}

